#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<deque>
<<<<<<< HEAD
#include<stack>
using namespace std;


class Solution {
public:
    int calculate(string s) {
        if(s.size()==1){
            return int(s[0]-'0');
        }
        deque<string> S;
        for(int i = 0;i<s.size();++i){
            if(s[i]==' '){

            }
            else if(S.empty()){
                string temp = "";
                S.push_back(temp+s[i]);
            }
            else if(s[i]>='0'&&s[i]<='9'){
                if(S.back()!="+"&&S.back()!="-"&&S.back()!="*"&&S.back()!="/"){
                    S.back() += s[i];
                }
                else{
                    string temp = "";
                    S.push_back(temp+s[i]);
                }
            }
            else{
                string temp = "";
                S.push_back(temp+s[i]);
            }
        }
        //再扫描一遍，把乘除解决
        stack<string> T;
        for(int i = 0;i<S.size();++i){
            if(S[i]=="*"||S[i]=="/"){
                if(S[i]=="*"){
                   T.top() = to_string(stoi(T.top())*stoi(S[i+1]));
                   i=i+1;
                }
                else{
                   T.top() = to_string(stoi(T.top())/stoi(S[i+1]));
                   i=i+1;
                }
            }
            else{
                T.push(S[i]);
            }
        }

        //遍历解决加减
        int result = 0;
        if(T.size()%2==0){
            while(!T.empty()){
                int temp = stoi(T.top());
                T.pop();
                if(T.top()=="-"){
                    temp *= -1;
                }
                result += temp;
            }
        }
        else{
            while(T.size()>1){
                int temp = stoi(T.top());
                T.pop();
                if(T.top()=="-"){
                    temp *= -1;
                }
                T.pop();
                result += temp; 
            }
            result += stoi(T.top());
        }


        return result;

    }

};

int main(){
    Solution S;
    cout<<S.calculate("111+999/111+999")<<endl;
}
=======
using namespace std;

class Solution {
public:
    int calculate(string s) {
        deque<string> S;
        for (int i = 0; i < s.size(); i++)
        {
            /* code */
            if(s[i]==' '){
                continue;
            }
            if(s[i]>='0'&&s[i]<='9'){
                if(S.back()>="0"&&S.back()<="9"){
                    S.back() = S.back()+s[i];
                }
                else{
                    S.push_back(s[i]);
                }
            }
        }
         
    }
};
>>>>>>> cf01110d1a883a01edf997edaf0ddeaa246634e5
